package folexpr.compiler;

import java.util.Collection;
import java.util.Iterator;
import java.util.Vector;

public class CompilerUtils
{
	
	public static void printList(Collection<String> varList, String listName)
	{
		System.out.print("Lista " + listName + " :");
		Iterator i = varList.iterator();
		while (i.hasNext()){
			String var = (String)i.next();
			System.out.print(" " + var + " ");
		}
		System.out.println();
	}
	
	public static String indent(int level,int indentationWidth)
	{
		String result = "";
		for(int i=0; i < level*indentationWidth ; i++)
		{
			result = result + " ";
		}
		return result;
	}

	public static String dumpList(Collection<String> list)
	{
		String result="[ ";
		boolean first=true;
		
		Iterator i = list.iterator();
		while (i.hasNext())
		{
			if (first)
			{
				result = result + (String)i.next();
				first=false;
			}
			else result = result + " , " + (String)i.next();
		}
		result = result + " ]" ;
		
		return result;
	
	}

	public static Vector<String> mergeElementiInAndVectors(Vector<String> a,Vector<String> b, boolean insideCong)
	{
		Vector<String> result = new Vector<String>();
		
		if (insideCong)
		{
			// unione dei due vettori
			result.addAll(a);
			result.addAll(b);
		}
		else
		{
			if ( a.isEmpty()) result = b;
			else	
			{
					// prodotto cartesiano dei due vettori
					Iterator it_a = a.iterator();
					while (it_a.hasNext())
					{
						String item_a = (String)it_a.next();
						
						Iterator it_b = b.iterator();
						while (it_b.hasNext())
						{
							String item_b = (String)it_b.next();
							
							// magari qui metti delle parentesi per star sicuro
							result.add(item_a + " " + CompilerConstants.orImage + " " + item_b);
						}
					}
			}
				
		}
		
		return result;
	}
	

}
